﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class MResultSceneUI : ResultSceneUI
{
    public GameObject fx;

    Coroutine m_ShowNextCoroutine;

    public GameObject[] delayShowObjs;
    
    public TapTimingView tapTimingView;

    public override void Awake()
    {
        base.Awake();

        if (fx)
        {
            var t = uiFXCamera.transform;
           // fx.transform.SetParent(PanelCommon.uiFXCamera.transform);
            
            //fx.transform.localPosition = new Vector3(0, Screen.height / 2,-19);
        }
        
        if (tapTimingView && tapTimingView.gameObject.activeSelf)
        {
            tapTimingView.Show(2, OnMulti);
        }
    }


    public override void Start()
    {
        base.Start();
        
        foreach (var delayShowObj in delayShowObjs)
        {
            delayShowObj.SetActive(false);
        }
        DoActionDelay.DelayAction(0.5f, () =>
        {
            foreach (var delayShowObj in delayShowObjs)
            {
                delayShowObj.SetActive(true);
            }
        });
                
        if (loseItBtn)
        {
            loseItBtn.SetActive(false);
            DoActionDelay.DelayAction(2, () =>
            { 
                if(tapTimingView.TapTimingButtonDock.gameObject.activeSelf);
                    loseItBtn.SetActive(true);
            });
        }
    }
    void OnMulti(int multi)
    {
        GameDebug.LogError($"gacha multi:{multi}");
#if UNITY_EDITOR
        this.GetComponentInParent<ResultUIViewController>().OnAdMulti(multi);
        return;
#endif
        AudioController.instance.PauseMusic();

        Game.Instance.adManager.PlayVideoAd(
            () =>
            {
                AudioController.instance.ResumeMusic();

                this.GetComponentInParent<ResultUIViewController>().OnAdMulti(multi);
            }
            , () =>
            {
                AudioController.instance.ResumeMusic();
            }, (err) =>
            {
                AudioController.instance.ResumeMusic();
                Game.Instance.ShowNoticePanel(Localization.instance.GetValue("ad_not_ready"));
            });
    }


}
